{$CLEO .cs}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP 

script_name "StBroom"

// By ArtemQa146

wait 500

:LoadedModels
wait 500
0AF0: 1@ = read_int_from_ini_file "cleo\StreetCleaners.ini" section "Models" key "Loaded1"
if
1@ == 1
jf @LoadedModels
1@ = 0 
0AF1: write_int 1@ to_ini_file "cleo\StreetCleaners.ini" section "Models" key "Loaded1"

0AF0: 0@ = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Settings" key "Street Cleaners"
if
    0@ == 0
then
    0A93: terminate_this_custom_script
end

0AF0: 6@ = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Street Cleaners" key "Ped ID Broom"
0AF0: 28@ = read_int_from_ini_file "cleo\StreetCleaners.ini" section "Models" key "Broom"

if
    6@ <= 0
then
    6@ = 183
end

// 1@ actor
// 0@ render
// 5@ particle
// 6@ Ped ID from ini


:Broom
wait 150
if 
   Player.Defined($PLAYER_CHAR)
jf @Broom
if and
$ACTIVE_INTERIOR == 0  
$ONMISSION == 0 
jf @Broom
0D59: get_current_weather_to 3@
0E40: get_current_hour 2@
if and
not 3@ == 8 // not weather rain 
not 3@ == 16 // not weather rain 2
2@ >= 6
14 >= 2@
jf @Broom

// LS

:Broom_Coords_1 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2354.3743 -1744.4265 13.5469 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2354.3743 -1744.4265 13.5469 radius 50.0
jf @Broom_Coords_2
// coords to walk
10@ = 2354.3743
11@ = -1744.4265
12@ = 13.5469
jump @Broom_Start

:Broom_Coords_2 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1475.4125 -1682.8898 14.0469 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1475.4125 -1682.8898 14.0469 radius 50.0
jf @Broom_Coords_3
// coords to walk
10@ = 1475.4125
11@ = -1682.8898
12@ = 14.0469
jump @Broom_Start

:Broom_Coords_3 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1176.2307 -2043.3689 69.0078 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1176.2307 -2043.3689 69.0078 radius 50.0
jf @Broom_Coords_4
// coords to walk
10@ = 1176.2307
11@ = -2043.3689
12@ = 69.0078
jump @Broom_Start

:Broom_Coords_4 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 397.7495 -1532.7122 32.2734 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 397.7495 -1532.7122 32.2734 radius 50.0
jf @Broom_Coords_5
// coords to walk
10@ = 397.7495
11@ = -1532.7122
12@ = 32.2734
jump @Broom_Start

:Broom_Coords_5 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1695.4659 -1279.4515 14.8114 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1695.4659 -1279.4515 14.8114 radius 50.0
jf @Broom_Coords_6
// coords to walk
10@ = 1695.4659
11@ = -1279.4515
12@ = 14.8114
jump @Broom_Start

:Broom_Coords_6 
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1682.2729 -2284.9941 -1.235  radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1682.2729 -2284.9941 -1.235 radius 50.0
jf @Broom_Coords_7
// coords to walk
10@ = 1682.2729
11@ = -2284.9941
12@ = -1.235
jump @Broom_Start


// LS Country

:Broom_Coords_7 
wait 100
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 662.3835 -458.2256 16.3359  radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 662.3835 -458.2256 16.3359 radius 50.0
jf @Broom_Coords_8
// coords to walk
10@ = 662.3835
11@ = -458.2256
12@ = 16.3359
jump @Broom_Start


// SF 

:Broom_Coords_8
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2717.2 377.0242 4.3705  radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2717.2 377.0242 4.3705  radius 50.0
jf @Broom_Coords_9
// coords to walk
10@ = -2717.2
11@ = 377.0242
12@ = 4.3705
jump @Broom_Start

:Broom_Coords_9
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos -1984.4316 582.3447 35.2677  radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos -1984.4316 582.3447 35.2677  radius 50.0
jf @Broom_Coords_10
// coords to walk
10@ = -1984.4316
11@ = 582.3447
12@ = 35.2677
jump @Broom_Start

:Broom_Coords_10
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos -1982.0156 883.9203 45.2031  radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos -1982.0156 883.9203 45.2031  radius 50.0
jf @Broom_Coords_11
// coords to walk
10@ = -1982.0156
11@ = 883.9203
12@ = 45.2031
jump @Broom_Start


:Broom_Coords_11
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos -1558.9105 1090.4629 7.1875  radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos -1558.9105 1090.4629 7.1875  radius 50.0
jf @Broom_Coords_12
// coords to walk
10@ = -1558.9105
11@ = 1090.4629
12@ = 7.1875
jump @Broom_Start

:Broom_Coords_12
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2600.3682 1385.5446 7.1723  radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2600.3682 1385.5446 7.1723  radius 50.0
jf @Broom_Coords_13
// coords to walk
10@ = -2600.3682
11@ = 1385.5446
12@ = 7.1723
jump @Broom_Start

// LV

:Broom_Coords_13
wait 100
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2021.3668 1167.7739 10.813  radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2021.3668 1167.7739 10.813  radius 50.0
jf @Broom_Coords_14
// coords to walk
10@ = 2021.3668
11@ = 1167.7739
12@ = 10.813
jump @Broom_Start

:Broom_Coords_14
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2170.4089 1668.861 10.8203  radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2170.4089 1668.861 10.8203  radius 50.0
jf @Broom_Coords_15
// coords to walk
10@ = 2170.4089
11@ = 1668.861
12@ = 10.8203
jump @Broom_Start

:Broom_Coords_15
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2316.9602 2288.3823 10.8203 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2316.9602 2288.3823 10.8203 radius 50.0
jf @Broom_Coords_16
// coords to walk
10@ = 2316.9602
11@ = 2288.3823
12@ = 10.8203
jump @Broom_Start

:Broom_Coords_16
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2370.7693 2337.009 4.9822 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2370.7693 2337.009 4.9822 radius 50.0
jf @Broom_Coords_17
// coords to walk
10@ = -2370.7693
11@ = 2337.009
12@ = 4.9822
jump @Broom_Start

:Broom_Coords_17
wait 100
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2134.886 -420.1781 35.3359 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2134.886 -420.1781 35.3359 radius 50.0
jf @Broom_Coords_18
// coords to walk
10@ = -2134.886
11@ = -420.1781
12@ = 35.3359
jump @Broom_Start

:Broom_Coords_18
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2682.437 -5.8864 6.1328 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2682.437 -5.8864 6.1328 radius 50.0
jf @Broom_Coords_19
// coords to walk
10@ = -2682.437
11@ = -5.8864
12@ = 6.1328
jump @Broom_Start

:Broom_Coords_19
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1068.7151 -1791.2791 13.6604 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1068.7151 -1791.2791 13.6604 radius 50.0
jf @Broom_Coords_20
// coords to walk
10@ = 1068.7151 
11@ = -1791.2791
12@ = 13.6604
jump @Broom_Start

:Broom_Coords_20
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1764.3306 -1892.907 13.5609 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1764.3306 -1892.907 13.5609 radius 50.0
jf @Broom_Coords_21
// coords to walk
10@ = 1764.3306 
11@ = -1892.907
12@ = 13.5609
jump @Broom_Start

:Broom_Coords_21
wait 100
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1113.3568 1611.9762 12.5469 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1113.3568 1611.9762 12.5469 radius 50.0
jf @Broom_Coords_22
// coords to walk
10@ = 1113.3568
11@ = 1611.9762
12@ = 12.5469
jump @Broom_Start

:Broom_Coords_22
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2629.1001 1824.3171 11.0234 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 2629.1001 1824.3171 11.0234 radius 50.0
jf @Broom_Coords_23
// coords to walk
10@ = 2629.1001 
11@ = 1824.3171
12@ = 11.0234
jump @Broom_Start

:Broom_Coords_23
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1652.1234 1945.9652 10.8203 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos 1652.1234 1945.9652 10.8203 radius 50.0
jf @Broom_Coords_24
// coords to walk
10@ = 1652.1234
11@ = 1945.9652
12@ = 10.8203
jump @Broom_Start

:Broom_Coords_24
if and
0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2270.9851 2391.8579 4.9492 radius 100.0
not locate_char_distance_to_coordinates $PLAYER_ACTOR pos -2270.9851 2391.8579 4.9492 radius 50.0
jf @Broom
// coords to walk
10@ = -2270.9851 
11@ = 2391.8579
12@ = 4.9492
jump @Broom_Start

:Broom_Start 
Model.Load(6@)
if
    not model.Available(6@)
then
    repeat
    wait 0
    model.Load(6@)
    until model.Available(6@)
end
038B: load_requested_models 

repeat
wait 0
04ED: load_animation  "PedEventsMod"
until 04EE:   animation "PedEventsMod" loaded

Actor.Create(1@, 21, 6@, 10@, 11@, 12@)   
0E24: fix_char 1@ ground 1 brightness 1 and_fade_in 0 
0F02:  1@ special_model 28@ bone 24 offset 0 0 0 rotation 0 0 0 scale 0@ // bone 34 left hand, 24 right hand, 9 had, 3 tors
0E30: set_render_object_auto_hide 0@ dead 1 weapon 1 car 1
0669: 5@ = create_attached_particle "vent" on_actor 1@ with_offset 0.496 -0.021 0.9 flag 1 
0883: attach_particle 5@ to_actor 1@ mode 24
0AC1: 7@ = load_audio_stream_with_3d_support "SQ/Broom.mp3" // IF and SET
0AC4: link_3d_audio_stream 7@ to_actor 1@
0ABC: set_audio_stream 7@ volume 0.0
Model.destroy(6@)
timera = 30000
29@ = 0

while true
wait 0
    if
        056D:   actor 1@ defined
    then
        if and
            0EE4: locate_char_distance_to_char $PLAYER_ACTOR char 1@ radius 150.0
            $ACTIVE_INTERIOR == 0
        then
        
            if and
                timera > 25000
                not Actor.Animation(1@) == "Sweep"
                not Actor.Animation(1@) == "SweepWalk"
            then
                0EFF: get_char_simplest_active_task 1@ id_to 2@ pointer_to 4@
                if or
                    2@ == 203 // task stand still
                    2@ == 900
                then
                    29@ = 0
                    0812: AS_actor 1@ perform_animation "Sweep" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 1 lockY 1 lockF 0 time -1
                    wait 100
                    0AAD: set_audio_stream 7@ state 1
                    0AC0: audio_stream 7@ looped 1
                    timerb = 0
                    continue
                end
            end

            if and
                not Actor.Animation(1@) == "Sweep"
                not Actor.Animation(1@) == "SweepWalk"
            then
                0AAD: set_audio_stream 7@ state 0
            end

            if
                0EE4: locate_char_distance_to_char $PLAYER_ACTOR char 1@ radius 20.0
            then
                0ABC: set_audio_stream 7@ volume 0.2
            else
                0ABC: set_audio_stream 7@ volume 0.0
            end
            
            if or
                Actor.Animation(1@) == "Sweep"
                Actor.Animation(1@) == "SweepWalk"
            then
                if
                    Actor.Animation(1@) == "Sweep"
                then
                    0613: 4@ = actor 1@ animation "Sweep" time
                end
                if
                    Actor.Animation(1@) == "SweepWalk"
                then
                    0613: 4@ = actor 1@ animation "SweepWalk" time
                end
                
                if
                    0EE4: locate_char_distance_to_char $PLAYER_ACTOR char 1@ radius 30.0
                then

                    // particle
                    if and
                        4@ >= 0.1
                        4@ <= 0.8
                    then
                        0EC0: add_fx_system_particle 5@ coord 0.4 -0.021 1.0 vel 0 0 0 size 0.8 brightness 0 rgba 1.0 1.0 0.9 0.1 lastFactor 0.4
                    end
                end

                // if animation ended, walk another position
                if
                    4@ >= 0.95
                then
                    if
                        0E4D: random_percent 70
                    then
                        0AAD: set_audio_stream 7@ state 0
                        0687: clear_actor 1@ task
                        wait 300
                        gosub @Rubbish
                        if
                            056D:   actor 1@ defined
                        then
                            0EFF: get_char_simplest_active_task 1@ id_to 2@ pointer_to 4@
                            if and
                                29@ == 0
                                2@ == 203 // task stand still
                            then
                                0A1A: actor 1@ perform_walk_animation "SweepWalk2" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                                05DE: AS_actor 1@ walk_around_ped_path
                            end
                        end
                        0209: timera = random_int_in_ranges 5000 15000
                        wait 500
                    else
                        timera = 0
                        wait 500 // for animation again
                    end
                    continue
                end
            end

            0D59: get_current_weather_to 3@
            0E40: get_current_hour 4@
            080E: get_actor 1@ ped_event_to 2@
            if or
                0118:   actor 1@ dead
                3@ == 8 // not weather rain
                3@ == 16 // not weather rain 2
                4@ >= 16 // timeout
                2@ == 9 // ped damaged
                2@ == 49 // shoot close ped
            then
                0AAE: remove_audio_stream 7@
                0650: destroy_particle 5@
                if 056D:   actor 1@ defined
                then 01C2: remove_references_to_actor 1@ // Like turning an actor into a random pedestrian
                end
                04EF: release_animation "PedEventsMod"
                jump @Broom
            end
            
            080E: get_actor 1@ ped_event_to 2@
            if or
                2@ == 15
                2@ == 31
                2@ == 59
            then
                0AAE: remove_audio_stream 7@
                0650: destroy_particle 5@
                if 056D:   actor 1@ defined
                then 01C2: remove_references_to_actor 1@ // Like turning an actor into a random pedestrian
                end
                04EF: release_animation "PedEventsMod"
                jump @Broom
            end
            
            //    
            if
                0457:   player $PLAYER_CHAR aiming_at_actor 1@
            then
                0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 2@
                0E89: get_weaponinfo_fire_type 2@ store_to 3@ //     
                if or
                    3@ == 1 //  
                    3@ == 3 //   (  ..)
                then
                    0AAE: remove_audio_stream 7@
                    0650: destroy_particle 5@
                    if 056D:   actor 1@ defined
                    then 01C2: remove_references_to_actor 1@ // Like turning an actor into a random pedestrian
                    end
                    04EF: release_animation "PedEventsMod"
                    jump @Broom
                end
            end
            
        gosub @Rubbish

            
            
        else
            gosub @Remove
            wait 1000
            jump @Broom
        end
    else
        gosub @Remove
        wait 1000
        jump @Broom
    end
end


:Remove
0AAE: remove_audio_stream 7@
0650: destroy_particle 5@
if 056D:   actor 1@ defined
then 009B: destroy_actor 1@
end
04EF: release_animation "PedEventsMod"
return

:Rubbish
30@ = 0
    while 0EA9: get_any_object_no_save_recursive 30@ progress_to 30@ object_to 31@
        if 856D:   not actor 1@ defined
        then break
        end
                
        if and
            09CC:   object 31@ model_is 2966
            0EE6: locate_char_distance_to_object 1@ object 31@ radius 20.0
            not is_object_script_controlled 31@
        then
            if or
                Actor.Animation(1@) == "Sweep"
                Actor.Animation(1@) == "SweepWalk"
            then
                if and
                    0EE6: locate_char_distance_to_object 1@ object 31@ radius 2.5
                    timerb > 500
                then
                    timerb = 0
                    0108: destroy_object 31@
                end
            else
                if and
                    not locate_char_distance_to_object 1@ object 31@ radius 2.5
                    29@ == 0
                then
                    0EFF: get_char_simplest_active_task 1@ id_to 2@ pointer_to 4@
                    if or
                        2@ == 203
                        2@ == 900
                    then
                        0400: store_coords_to 10@ 11@ 12@ from_object 31@ with_offset 0.0 0.0 0.0
                        0A1A: actor 1@ perform_walk_animation "SweepWalk2" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                        07CD: AS_actor 1@ walk_to 10@ 11@ 12@ stop_with_angle 0.0 within_radius 1.0
                        timera = 0
                        29@ = 1
                        wait 300
                        break
                    end
                else
                    if
                        locate_char_distance_to_object 1@ object 31@ radius 1.5
                    then
                        timera = 30000
                    end
                end
            end
        end
    end
return

// By ArtemQa146